<?php
namespace jy_newczfee;
defined('BY_JYA') or exit('error');
/*
	分红插件会员类
*/
class member extends \plugin{
	public function check_redfee($member=array()){
		return '';
	}
	public function apply_agent($mid,$member_update=array()){
		$apply=$this->get('apply',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid));
		if(!$apply['id']){
			$member_update['uniacid']=$_SESSION['uniacid'];
			$member_update['mid']=$mid;
			$member_update['createtime']=TIMESTAMP;
			$this->insert('apply',$member_update);
			$apply=$this->get('apply',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid));
		}else{
			$member_update['status']=0;
			$this->update('apply',$member_update,array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
		}
		$this->model('notice')->notice_apply($apply);
		return true;
	}
	/*
		审核分红商
	*/
	public function check_apply($apply_id,$status,$remark=''){
		if(!$apply_id || !$status){
			return;
		}
		$apply=$this->get('apply',array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$apply){
			return;
		}
		$update=array(
			'complete_time'=>TIMESTAMP,
		);
		if($status==1){
			$update['status']=3;
			if(!$this->setting['biglevelid']){
				exi('请先基本设置--大客户会员等级绑定','error');
			}
			model('jy_weishop/member')->up_member_level($apply['mid'],$this->setting['biglevelid'],0,7);
			$member=pdo_get('jy_weishop_member',array('mid'=>$apply['mid'],'uniacid'=>$_SESSION['uniacid'],'merchid'=>0),array('level','viptime'));
			$update['oldlevelid']=$member['level'];
		}else{
			$update['status']=$status;
			$update['remark']=$remark;
		}
		$this->update('apply',$update,array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function check_apply2($apply_id,$status,$remark=''){
		if(!$apply_id || !$status){
			return;
		}
		$apply=$this->get('apply',array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$apply){
			return;
		}
		$update=array(
			'complete_time2'=>TIMESTAMP,
		);
		if($status==1){
			$update['status']=1;
			if(!$this->setting['biglevelid']){
				exi('请先基本设置--大客户会员等级绑定','error');
			}
			model('jy_weishop/member')->up_member_level($apply['mid'],$this->setting['biglevelid'],0,7);
		}else{
			$update['status']=$status?5:4;
			$update['remark']=$remark;
			if($status){
				model('jy_weishop/member')->up_member_level($apply['mid'],$apply['oldlevelid'],0,7);
			}
		}
		$this->update('apply',$update,array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
	public function check_apply3($apply_id){
		if(!$apply_id){
			return;
		}
		$apply=$this->get('apply',array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		if(!$apply){
			return;
		}
		$videomonthday=$this->setting['videomonthday']*24*3600+$apply['complete_time'];
		if($videomonthday>time()){
			return $videomonthday;
		}
		$update=array(
			'complete_time2'=>TIMESTAMP,
		);
		model('jy_weishop/member')->up_member_level($apply['mid'],$apply['oldlevelid'],0,7);
		$this->update('apply',$update,array('id'=>$apply_id,'uniacid'=>$_SESSION['uniacid']));
		return true;
	}
}